/*
 * Syntelos 'SX'
 * Copyright (C) 1998, 2007  John Pritchard.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 */
package syntelos.sx.methods;

import alto.io.Output;
import alto.lang.Address;
import alto.lang.Component;
import alto.lang.Type;

/**
 * The request line path is a Hexidecimal type address.  Return the
 * mimetype string for the type hash.
 * 
 * For example <pre> TYPEFOR /6578742f68746d18 </pre> will respond
 * with <pre> text/html </pre>
 * 
 * For example <pre> TYPEFOR /cafebabe </pre> will produce a "not
 * found" response.
 * 
 * For example <pre> TYPEFOR /index.html </pre> will produce an
 * "error" response.
 * 
 * 
 * 
 * @see alto.lang.Type
 * @since 1.6
 */
public class Typefor
    extends syntelos.sx.Response
{

    public Typefor(){
        super();
    }


    public void respond(syntelos.sx.Request req)
        throws java.io.IOException,
               java.lang.InterruptedException
    {
        String Hex = Component.Tools.Clean(req.getPath());
        if (null != Hex){
            this.setContentTypeText();
            byte[] bits = alto.io.u.Hex.decode(Hex);
            if (null != bits){
                Component.Type component = Component.Type.Tools.ValueOf(bits);
                Type type = Type.Tools.For(component);
                if (null != type){
                    this.println(type.toString());
                    return ;
                }
            }
        }
        this.setStatusNotFound();
    }

}
